#include "stdafx.h"
#include "histroy_color_btn.h"
#include "bmp_file_op.h"
#include "frame_top.h"
#include <utility/api_tools.h>
#include "dll_object.h"

histroy_color_btn::histroy_color_btn()
{
	this->pwnd_ = NULL;
}

histroy_color_btn::~histroy_color_btn()
{

};

BEGIN_MESSAGE_MAP(histroy_color_btn, CButton)
	//{{AFX_MSG_MAP(defcolor_btn)
	ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void histroy_color_btn::OnClicked()
{
	CRect rt,rc;
	GetWindowRect(rc);
	::GetWindowRect(this->pwnd_->GetSafeHwnd(), rt);
	
	int left = rc.left - rt.left;
	int top = rc.top - rt.top;
	left -= 6;
	top -= 5;
	CPoint p;
	p.x = (left + left + rc.Width()) / 2;
	p.y = (top + top + rc.Height()) / 2;

	RGBQUAD rgbcx = this->pcx_image_->GetPixelColor(p.x, 65 - p.y);
	//bmp_file_op op;
	//BOOL ret = op.bopen(defcolor_path.c_str());
	//if( !ret )
	//{
	//	return;
	//}
	////bmphsl hsl;
	//bmprgb rgb;
	//ret = op.get_pixel(p, rgb, e_bmp_rgb);
	//op.bclose();
	//int h = hsl.h;
	//int s = hsl.s;
	//int l = hsl.l;
	/*int r = rgb.r;
	int g = rgb.g;
	int b = rgb.b;*/

	COLORREF col = RGB(rgbcx.rgbRed,rgbcx.rgbGreen,rgbcx.rgbBlue);
	dsAdjustColor2(col);
	//dsAdjustColor(h, s, l);
	g_dll_obj->im_->dispatch_sys_event(aot::tt::imain::regist_sys_event_t::e_type_ui, WM_GLB_UI_CONFIG_CHANGE, 0, 0);
}